package fudan.se.project.repository.entity.message;


import fudan.se.project.domain.conference.Conference;
import fudan.se.project.domain.User;
import fudan.se.project.domain.message.Invitation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;


@Repository
public interface InvitationRepository extends PagingAndSortingRepository<Invitation, Long> {

    Invitation findById(long id);

    Page<Invitation> findBySender(User sender, Pageable pageable);

    Page<Invitation> findByReceiver(User receiver, Pageable pageable);

    @Query(value = "select invitation from Invitation invitation " +
            "where invitation.sender=:sender " +
            "and invitation.receiver=:receiver " +
            "and invitation.conference=:conference " +
            "and invitation.state=:state")
    Invitation findBySenderAndReceiverWithStateInConference(User sender, User receiver,
                                                            Conference conference, Invitation.State state);
}
